package com.cloud.force.api.web;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.force.api.bean.MenuTabAuthority;
import com.cloud.force.api.bean.Part;
import com.cloud.force.api.entity.TaskListTab;
import com.cloud.force.api.entity.TaskListTabGroup;
import com.cloud.force.api.service.TaskListTabService;
import com.cloud.force.common.result.Quokka;
import com.cloud.force.interfaces.FeignClientFreeflow;

@RestController
@RequestMapping("force/api/tasklist/tab")
public class TaskListTabController {

	@Autowired
	private TaskListTabService taskListTabService;

	@Autowired
	private FeignClientFreeflow feignFreeflowClient;

	@GetMapping("/listtree")
	public Quokka listTree() {
		return new Quokka(true, taskListTabService.listTree());
	}

	@RequestMapping("/groups")
	public Quokka listGroups() {
		return new Quokka(true, taskListTabService.listTaskListTabHeader());
	}

	@RequestMapping("/listauthority")
	public Quokka listPartAuthority(long taskListId, long actDefId) {
		List<Part> parts = feignFreeflowClient.loadPartsByActDef(actDefId);
		return new Quokka(true, taskListTabService.listPartAuthority(taskListId, actDefId, parts));
	}

	@RequestMapping("/saveupdate")
	public Quokka saveUpdatePartAuth(@RequestBody List<MenuTabAuthority> parts, long actDefId, long taskListId) {
		taskListTabService.saveUpdatePartAuth(parts, actDefId, taskListId);
		return new Quokka(true);
	}

	@RequestMapping("/listbypart")
	public Quokka listTaskListMenuPart(long taskListId, long actDefId) {
		List<Long> parts = new ArrayList<Long>();
		parts.add(1L);
		return new Quokka(true, taskListTabService.listTaskListPartByPart(taskListId, actDefId, parts));
	}

	@PostMapping("/group/saveupdate")
	public Quokka saveUpdateGroup(@RequestBody TaskListTabGroup group) {
		return new Quokka(true, taskListTabService.saveUpdateGroup(group));
	}

	@GetMapping("/group/delete")
	public Quokka deleteGroup(long groupId) {
		taskListTabService.deleteGroup(groupId);
		return new Quokka(true);
	}

	@PostMapping("saveupdate")
	public Quokka saveUpdateTab(@RequestBody TaskListTab tab) {
		return new Quokka(true, taskListTabService.saveUpdateTaskListTab(tab));
	}

	@GetMapping("delete")
	public Quokka deleteTab(long menuId) {
		return new Quokka(true, taskListTabService.deleteTab(menuId));
	}

	@GetMapping("load")
	public Quokka loadTab(long menuId) {
		return new Quokka(true, taskListTabService.loadTab(menuId));
	}
}
